﻿using System;
using System.Web;
using System.Web.Mvc;

namespace JustSiteWorker.Helpers
{
    public static class CustomHtmlHelpers
    {
        public static string GetNamedLink(this HtmlHelper helper, User user, HttpRequestBase request)
        {
            if (user == null || string.IsNullOrEmpty(user.UrlId)) return string.Empty;

            string domain = request.Url.Scheme + System.Uri.SchemeDelimiter + request.Url.Host + (request.Url.IsDefaultPort ? "" : ":" + request.Url.Port);

            return string.Format("{0}/Login/{1}", domain, user.UrlId);
        }

        public static bool IsOnline(this HtmlHelper helper, User user)
        {
            if (user == null || user.LastVisit == null) return false;

            return (DateTime.Now - (DateTime)user.LastVisit).TotalMilliseconds > 600000 ? false : true;
        }

        public static string LastUserActiv(this HtmlHelper helper, User user)
        {
            if (user == null || user.LastVisit == null) return string.Empty;

            return ((DateTime)user.LastVisit).ToString("hh:mm dd.MM.yyyy");
        }
    }
}